Code Examples

The code examples can be viewed online or downloaded and run. To download and run, click download, unzip the zip file, and execute the RUN.BAT file (for Windows systems). This RUN.BAT assumes that you have the Java interpreter in your PATH. Note: If you have JBuilder, you might want to look at the source in JBuilder rather than online.

Skeleton of an Application: This example is meant to be the absolute minimum amount of code needed to code an application. View

Skeleton of an Applet: This example is meant to be the absolute minimum amount of code needed to code an applet. View

Supplier Class Example: This example demonstrates many ideas we've presented in class. It's a Car class that can accept the drive message and its fuel is adjusted according to the driving activity. Concepts illustrated include constructors, methods declarations, method calls, constants, class variables (versus instance variables), arrays, this, string literals, and local variables. View Download

Inheritance Example: This example demonstrates inheritance. Concepts illustrated include the abstract reserved word, calling superclass methods, calling superclass constructors, overriding methods, and class hierarchies. This example runs from problem definition to complete solution. Download problem description and runnable code. You can either execute RUN.BAT or load it using the included JBuilder project.

Interface Example: This example is a more complete version of the juggle example from class. Concepts illustrated include interface creation, implementation, and the fact that interfaces create new types. The main class is interface.Hello. Running it is not exciting as it displays nothing. You should understand the code and the motivation for using interfaces. Download.

Exception Example: This example demonstrates a try-catch statement. ArrayProblems is not exciting as it displays nothing. But delete the try-catch and watch the exception get thrown. NumberFormatProblems is a more practical example. Download.

Input/Output Example: This example demonstrates file input and output. ConsoleToFile reads successive lines from the keyboard and writes them to a file. FileToArray reads integers from a file and stores them in an array. Download.

Collection Example: This set of classes demonstrates various things from the collections framework. Concepts illustrated include sets, lists, maps, iterators, and sorting. Download.

GUI Example: This set of classes demonstrates the use of various GUI components. Download.